package com.hnchances.common.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
@ApiModel(value = "ResultVo对象",description = "封装接口返回给前端的数据")
public class ResultVo {
    // 响应给前端的状态码
    @ApiModelProperty(value = "响应状态码",dataType = "int")
    private Integer code;
    // 响应给前端的提示信息
    @ApiModelProperty(value = "响应提示信息",dataType = "string")
    private String message;
    // 响应给前端的数据
    @ApiModelProperty(value = "响应数据",dataType = "map")
    private Map<String, Object> data = new HashMap<>();

    private ResultVo() {
    }

    public static ResultVo ok() {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(Code.SUCCESS);
        resultVo.setMessage("成功");
        return resultVo;
    }

    public static ResultVo error() {
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(Code.ERROR);
        resultVo.setMessage("失败");
        return resultVo;
    }

    public ResultVo message(String message){
        this.setMessage(message);
        return this;
    }
    public ResultVo code(Integer code){
        this.setCode(code);
        return this;
    }
    public ResultVo data(String key,Object value){
        this.data.put(key,value);
        return this;
    }
    public ResultVo data(Map<String,Object> map){
        this.setData(map);
        return this;
    }
}
